<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Dumps a string representation of an internal zend value to output</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.debug-zval-dump" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">debug_zval_dump</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.2.0, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">debug_zval_dump</span> &mdash; <span class="dc-title">Dumps a string representation of an internal zend value to output</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.debug-zval-dump-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>debug_zval_dump</strong></span>
    ( <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$variable</code></span>
   [, <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$...</code></span>
  ] ) : <span class="type"><span class="type void">void</span></span></div>

  <p class="para rdfs-comment">
   Dumps a string representation of an internal zend value to output.
  </p>
 </div>

 <div class="refsect1 parameters" id="refsect1-function.debug-zval-dump-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">variable</code></dt>

     <dd>

      <p class="para">
       The variable being evaluated.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.debug-zval-dump-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   没有返回值。
  </p>
 </div>

 <div class="refsect1 examples" id="refsect1-function.debug-zval-dump-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-6355">
    <p><strong>Example #1 <span class="function"><strong>debug_zval_dump()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$var1&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'Hello&nbsp;World'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$var2&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">''</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$var2&nbsp;</span><span style="color: #007700">=&amp;&nbsp;</span><span style="color: #0000BB">$var1</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">debug_zval_dump</span><span style="color: #007700">(&amp;</span><span style="color: #0000BB">$var1</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
&amp;string(11) &quot;Hello World&quot; refcount(3)
</pre></div>
    </div>
   </div>
  </p>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <strong>Beware the <em>refcount</em></strong><br />
   <p class="para">
    The <em>refcount</em> value returned by this function is
    non-obvious in certain circumstances. For example, a developer might
    expect the above example to indicate a <em>refcount</em> of
    <em>2</em>. The third reference is created when actually
    calling <span class="function"><strong>debug_zval_dump()</strong></span>.
   </p>
   <p class="para">
    This behavior is further compounded when a variable is not passed to
    <span class="function"><strong>debug_zval_dump()</strong></span> by reference. To illustrate, consider
    a slightly modified version of the above example:
   </p>
   <p class="para">
    <div class="example" id="example-6356">
     
     <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$var1&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'Hello&nbsp;World'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$var2&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">''</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$var2&nbsp;</span><span style="color: #007700">=&amp;&nbsp;</span><span style="color: #0000BB">$var1</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">debug_zval_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$var1</span><span style="color: #007700">);&nbsp;</span><span style="color: #FF8000">//&nbsp;not&nbsp;passed&nbsp;by&nbsp;reference,&nbsp;this&nbsp;time<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
     </div>

     <div class="example-contents"><p>以上例程会输出：</p></div>
     <div class="example-contents screen">
<div class="cdata"><pre>
string(11) &quot;Hello World&quot; refcount(1)
</pre></div>
     </div>
    </div>
   </p>
   <p class="para">
    Why <em>refcount(1)</em>? Because a copy of <em>$var1</em> is
    being made, when the function is called.
   </p>
   <p class="para">
    This function becomes even <em class="emphasis">more</em> confusing when a
    variable with a <em>refcount</em> of <em>1</em> is
    passed (by copy/value):
   </p>
   <p class="para">
    <div class="example" id="example-6357">
     
     <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$var1&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'Hello&nbsp;World'</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">debug_zval_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$var1</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
     </div>

     <div class="example-contents"><p>以上例程会输出：</p></div>
     <div class="example-contents screen">
<div class="cdata"><pre>
string(11) &quot;Hello World&quot; refcount(2)
</pre></div>
     </div>
    </div>
   </p>
   <p class="para">
    A <em>refcount</em> of <em>2</em>, here, is extremely
    non-obvious. Especially considering the above examples. So what&#039;s
    happening?
   </p>
   <p class="para">
    When a variable has a single reference (as did <em>$var1</em>
    before it was used as an argument to <span class="function"><strong>debug_zval_dump()</strong></span>),
    PHP&#039;s engine optimizes the manner in which it is passed to a function.
    Internally, PHP treats <em>$var1</em> like a reference (in that
    the <em>refcount</em> is increased for the scope of this
    function), with the caveat that <em class="emphasis">if</em> the passed reference
    happens to be written to, a copy is made, but only at the moment of
    writing. This is known as &quot;copy on write.&quot;
   </p>
   <p class="para">
    So, if <span class="function"><strong>debug_zval_dump()</strong></span> happened to write to its sole
    parameter (and it doesn&#039;t), then a copy would be made. Until then, the
    parameter remains a reference, causing the <em>refcount</em> to
    be incremented to <em>2</em> for the scope of the function call.
   </p>
  </p></blockquote>
 </div>

 <div class="refsect1 seealso" id="refsect1-function.debug-zval-dump-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="var_dump.html" class="function" rel="rdfs-seeAlso">var_dump()</a> - 打印变量的相关信息</span></li>
    <li class="member"><span class="function"><a href="debug_backtrace.html" class="function" rel="rdfs-seeAlso">debug_backtrace()</a> - 产生一条回溯跟踪(backtrace)</span></li>
    <li class="member"><a href="language.references.html" class="link">References Explained</a></li>
    <li class="member"><a href="http://derickrethans.nl/php_references_article.php" class="link external">&raquo;&nbsp;References Explained (by Derick Rethans)</a></li>
   </ul>
  </p>
 </div>

</div></div></div></body></html>